package net.java.mediasystems.web.datamodel;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import net.java.mediasearch.model.SmallMediaEntity;

public class SmallMediaEntityDataModel extends ListDataModel<SmallMediaEntity> implements SelectableDataModel<SmallMediaEntity> {

	/**
	 * Default Constructor
	 */
	public SmallMediaEntityDataModel() {
		super();
	}
	
	/**
	 * Extended Constructor with given List for Data.
	 * 
	 * @param data List<SmallMediaEntity>
	 */
	public SmallMediaEntityDataModel(List<SmallMediaEntity> data) {
		super(data);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object getRowKey(SmallMediaEntity object) {
		return object.getId();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public SmallMediaEntity getRowData(String rowKey) {
		return findSmallMediaEntityById(rowKey);
	}
	
	@SuppressWarnings("unchecked")
	private SmallMediaEntity findSmallMediaEntityById(String id) {
		for (SmallMediaEntity curSmallMediaEntity : ((List<SmallMediaEntity>) this.getWrappedData())) {
			if (curSmallMediaEntity.getId().equals(id)) {
				return curSmallMediaEntity;
			}
		}
		return null;	// Should never be the case!
	}
}
